<?php

/*模板里引用模板*/
function include_file($tplname,$view = 'View'){
	$var = Regsiter::getInterface();
	$view = $var->get($view);
	$config = $var->get('Config');
	$filename = $config['tpl_path'].'/'.$config['style'].'/'.$tplname;
	$view_array = $view->getArray();

	if(file_exists($filename) && !is_dir($filename))
	{
		if(isset($view_array) && !empty($view_array)){
			extract($view_array,EXTR_PREFIX_ALL,'view');
		}
		include $filename;
	}
	else
		trigger_error("没有找到这个模板{$filename}", E_USER_ERROR);
}


/*导入包*/
function import($modelpack,$path='',$modelpre = '.model'){
	if($path != '')
	{
		$path = str_replace('.','/',$path);
		require_once $path . '/' . $modelpack . $modelpre.'.php';
	}else{
		require_once $modelpack . $modelpre . '.php';
	}
}
/*可能被移除 2012-06-24*/
/*
function model($name){
	$filename =  app_path.'./model/'.$name.'.model.php';
	if(file_exists($filename) && is_file($filename)){
		include_once($filename);
    }else{
		trigger_error("没有定义过'{$name}'模块", E_USER_ERROR);
	}
}
*/
function dstripslashes($string) {
	if(empty($string)) return $string;
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = dstripslashes($val);
		}
	} else {
		$string = stripslashes($string);
	}
	return $string;
}
function daddslashes($string, $force = 0, $strip = FALSE) {
	if(!MAGIC_QUOTES_GPC || $force) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = daddslashes($val, $force, $strip);
			}
		} else {
			$string = addslashes($strip ? stripslashes($string) : $string);
		}
	}
	return $string;
}